
/** 监听元素大小 */
export function onResize(el: HTMLElement, callback: (ev: Event) => any) {
  const hasobject = el.querySelector("object");
  if (hasobject) {
    return;
  }
  const objEl = document.createElement("object");
  objEl.type = "text/html";
  objEl.data = "about:blank";
  objEl.setAttribute("style", `
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      overflow: hidden;
      opacity: 0;
      pointer-events: none;
      z-index: -1;
  `);
  objEl.onload = (evt) => {
    if (objEl.contentDocument && objEl.contentDocument.defaultView) {
      objEl.contentDocument.defaultView.addEventListener("resize", (ev) => {
        callback(ev);
      });
    }
    callback(evt);
  };
  el.appendChild(objEl);
}
